home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / zaxxon.c < prev   
C/C++ Source or Header  |  2000-04-04  |  4KB  |  179 lines

  1. /*
  2.  * Zaxxon Soundhardware Driver
  3.  * Copyright Alex Judd 1997/98
  4.  */
  5.  
  6. /***************************************************************************
  7.  
  8. Sound interface is provided by an 8255. The 8255 is a parallel peripheral
  9. interface, used also in Scramble. It has three 8-bit outputs.
  10. All sounds are generated by discrete circuits. Each sound is triggered by
  11. an output pin of the 8255.
  12.  
  13. Zaxxon Sound Information: (from the schematics)
  14. by Frank Palazzolo
  15.  
  16. There are four registers in the 8255. they are mapped to
  17. (111x xxxx 0011 11pp) by Zaxxon.  Zaxxon writes to these
  18. at FF3C-FF3F.
  19.  
  20. There are three modes of the 8255, but by the schematics I
  21. can see that Zaxxon is using "Mode 0", which is very simple.
  22.  
  23. Important Note:
  24. These are all Active-Low outputs.
  25. A 1 De-activates the sound, while a 0 Activates/Triggers it
  26.  
  27. Port A Output:
  28. FF3C bit7 Battleship
  29.      bit6 Laser
  30.      bit5 Base Missle
  31.      bit4 Homing Missle
  32.      bit3 Player Ship D
  33.      bit2 Player Ship C
  34.      bit1 Player Ship B
  35.      bit0 Player Ship A
  36.  
  37. Port B Output:
  38. FF3D bit7 Cannon
  39.      bit6 N/C
  40.      bit5 M-Exp
  41.      bit4 S-Exp
  42.      bit3 N/C
  43.      bit2 N/C
  44.      bit1 N/C
  45.      bit0 N/C
  46.  
  47. Port C Output:
  48. FF3E bit7 N/C
  49.      bit6 N/C
  50.      bit5 N/C
  51.      bit4 N/C
  52.      bit3 Alarm 3
  53.      bit2 Alarm 2
  54.      bit1 N/C
  55.      bit0 Shot
  56.  
  57. Control Byte:
  58. FF3F Should be written an 0x80 for Mode 0
  59.      (Very Simple) operation of the 8255
  60.  
  61. ***************************************************************************/
  62.  
  63. #include "driver.h"
  64.  
  65.  
  66. #define TOTAL_SOUNDS 22
  67. int soundplaying[TOTAL_SOUNDS];
  68.  
  69. struct sa
  70. {
  71.     int channel;
  72.     int num;
  73.     int looped;
  74.     int stoppable;
  75.     int restartable;
  76. };
  77.  
  78. struct sa sa[TOTAL_SOUNDS] =
  79. {
  80.     {  0,  0, 1, 1, 1 },    /* Line  4 - Homing Missile  (channel 1) */
  81.     {  1,  1, 0, 1, 1 },    /* Line  5 - Base Missile */
  82.     {  2,  2, 1, 1, 1 },    /* Line  6 - Laser (force field) (channel 1) */
  83.     {  3,  3, 1, 1, 1 },    /* Line  7 - Battleship (end of level boss) (channel 1) */
  84.     { -1 },                    /* Line  8 - unused */
  85.     { -1 },                    /* Line  9 - unused */
  86.     { -1 },                    /* Line 10 - unused */
  87.     { -1 },                    /* Line 11 - unused */
  88.     {  4,  4, 0, 0, 1 },    /* Line 12 - S-Exp (enemy explosion) */
  89.     {  5,  5, 0, 0, 0 },    /* Line 13 - M-Exp (ship explosion) (channel 1) */
  90.     { -1 },                    /* Line 14 - unused */
  91.     {  6,  6, 0, 0, 1 },    /* Line 15 - Cannon (ship fire) */
  92.     {  7,  7, 0, 0, 1 },    /* Line 16 - Shot (enemy fire) */
  93.     { -1 },                    /* Line 17 - unused */
  94.     {  8,  8, 0, 0, 1 },    /* Line 18 - Alarm 2 (target lock) */
  95.     {  9,  9, 0, 0, 0 },    /* Line 19 - Alarm 3 (low fuel) (channel 1) */
  96.     { -1 },                    /* Line 20 - unused */
  97.     { -1 },                    /* Line 21 - unused */
  98.     { -1 },                    /* Line 22 - unused */
  99.     { -1 },                    /* Line 23 - unused */
  100.     { 10, 10, 1, 1, 1 },    /* background */
  101.     { 11, 11, 1, 1, 1 },    /* background */
  102. };
  103.  
  104.  
  105.  
  106. WRITE_HANDLER( zaxxon_sound_w )
  107. {
  108.     int line;
  109.     int noise;
  110.  
  111.  
  112.     if (offset == 0)
  113.     {
  114.         /* handle background rumble */
  115.         switch (data & 0x0c)
  116.         {
  117.             case 0x04:
  118.                 soundplaying[20] = 0;
  119.                 sample_stop(sa[20].channel);
  120.                 if (soundplaying[21] == 0)
  121.                 {
  122.                     soundplaying[21] = 1;
  123.                     sample_start(sa[21].channel,sa[21].num,sa[21].looped);
  124.                 }
  125.                 sample_set_volume(sa[21].channel,128 + 40 * (data & 0x03));
  126.                 break;
  127.             case 0x00:
  128.             case 0x08:
  129.                 if (soundplaying[20] == 0)
  130.                 {
  131.                     soundplaying[20] = 1;
  132.                     sample_start(sa[20].channel,sa[20].num,sa[20].looped);
  133.                 }
  134.                 sample_set_volume(sa[20].channel,128 + 40 * (data & 0x03));
  135.                 soundplaying[21] = 0;
  136.                 sample_stop(sa[21].channel);
  137.                 break;
  138.             case 0x0c:
  139.                 soundplaying[20] = 0;
  140.                 sample_stop(sa[20].channel);
  141.                 soundplaying[21] = 0;
  142.                 sample_stop(sa[21].channel);
  143.                 break;
  144.         }
  145.     }
  146.  
  147.     for (line = 0;line < 8;line++)
  148.     {
  149.         noise = 8 * offset + line - 4;
  150.  
  151.         /* the first four sound lines are handled separately */
  152.         if (noise >= 0)
  153.         {
  154.             if ((data & (1 << line)) == 0)
  155.             {
  156.                 /* trigger sound */
  157.                 if (soundplaying[noise] == 0)
  158.                 {
  159.                     soundplaying[noise] = 1;
  160.                     if (sa[noise].channel != -1)
  161.                     {
  162.                         if (sa[noise].restartable || !sample_playing(sa[noise].channel))
  163.                             sample_start(sa[noise].channel,sa[noise].num,sa[noise].looped);
  164.                     }
  165.                 }
  166.             }
  167.             else
  168.             {
  169.                 if (soundplaying[noise])
  170.                 {
  171.                     soundplaying[noise] = 0;
  172.                     if (sa[noise].channel != -1 && sa[noise].stoppable)
  173.                         sample_stop(sa[noise].channel);
  174.                 }
  175.             }
  176.         }
  177.     }
  178. }
  179.